import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set( 200, 200,200 );
camera.lookAt(0, 0, 0);
const axesHelper = new THREE.AxesHelper( 200 );
// scene.add( axesHelper );

const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const controls = new OrbitControls(camera, renderer.domElement);

const pointLight = new THREE.PointLight( 0xffffff, 1, 1000 );
pointLight.position.set( 100, 100, 100 );
scene.add( pointLight );

// 虚线材质
const boxGeometry = new THREE.BoxGeometry( 100, 100, 100 );
const geometry = new THREE.EdgesGeometry( boxGeometry );
const material = new THREE.LineDashedMaterial( {
    color: 0xffffff,
    dashSize: 10,
    gapSize: 5
} );
const line = new THREE.Line( geometry, material );
line.position.set( 200, 0, 0 );
line.computeLineDistances(); // Required for dashed lines
scene.add( line );

// 网格模型材质颜色
const geometry2 = new THREE.PlaneGeometry( 100, 100, 10, 10 );
const material2 = new THREE.MeshBasicMaterial( {
    color: 0x00ff00,
    wireframe: false,
    side: THREE.DoubleSide,
    // 透明度transparent和opacity两参数控制透明度
    transparent: true,
    opacity: 0.5,
} );
const planeMesh = new THREE.Mesh( geometry2, material2 );
planeMesh.position.set( 0, 200, 0 );
scene.add( planeMesh );

// 网格模型材质贴图
const geometry3 = new THREE.SphereGeometry( 100 );
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load( '/assets/image/diqiu.awebp' );
texture.colorSpace = THREE.SRGBColorSpace; // 设置颜色空间
const material3 = new THREE.MeshBasicMaterial( {
    map: texture,
    // aoMap: texture,
} );
const sphereMesh = new THREE.Mesh( geometry3, material3 );
// sphereMesh.position.set( 200, 0, 0 );
scene.add( sphereMesh );

function animate() {
    renderer.render( scene, camera );
    requestAnimationFrame( animate );
}
animate();